 (function() {

     angular.module('BlurAdmin.pages.ConsultingM')
         .controller('ConsultingMCtrl', ConsultingMCtrl);

     function ConsultingMCtrl($scope, $datepicker, $uibModal, taRegisterTool, $mydialog, $ShareData, $myconfig, $http) {
         //弹窗框
         $scope.is_suer_root = is_suer_root;
         console.log(is_suer_root.news);
         $scope.open = function(page, size) {
             var opt = $uibModal.open({
                 animation: true,
                 templateUrl: page,
                 size: size,
                 scope: $scope,
                 backdrop: 'static',
                 resolve: {
                     items: function() {
                         return $scope.items;
                     }
                 }
             });
             $scope.opt_close = opt.close;
         };


         //日期插件
         $scope.format = "yyyy/MM/dd";
         $scope.altInputFormats = ['yyyy/M!/d!'];
         $scope.dat = {
             dat1: $datepicker.dataNew(),
             dat2: $datepicker.dataNew(),
             dat3: $datepicker.dataNew(),
             dat4: $datepicker.dataNew(),
         }

         $scope.maxStartDate = new Date();




         //新增咨询
         $scope.xinzeng = function() {
             $ShareData.setNewConsu('');
             $scope.open('app/pages/ConsultingM/newConsulting.html', 'lg');
         }

         //编辑咨询
         $scope.edit = function(val) {
             $ShareData.setNewConsu(val);
             $scope.open('app/pages/ConsultingM/newConsulting.html', 'lg');
         }

         //点击分页事件

         $scope.pageChanged = function(val) {
             var Page_num = val //选中的页面数
             $scope.search_data.page = val;
             $scope.news_list_b();
         };



         //判断查询条件
         $scope.search_data = {
             page: 1, //当前所在页数
             limit: 5, //每页显示多少条
             title: '', //标题
             start_time: $scope.dat.dat3.date_, //开始时间
             end_time: $scope.dat.dat4.date_, //结束时间
         }


         //获取列表总数
         $scope.News_count_b = function() {
             var data1 = document.getElementById("dat1") ? document.getElementById("dat1").value : null;
             var data2 = document.getElementById("dat2") ? document.getElementById("dat2").value : null;
             var opt = $scope.search_data;
             opt.start_time = data1;
             opt.end_time = data2;
             $http.get($myconfig.api.Consulting_news_count_b, {
                 params: opt
             }).then(function(res) {
                 //分页定义数据
                 $scope.bigTotalItems = res.data.data;
                 $scope.news_list_b();
             });
         };

         //咨询列表
         $scope.news_list_b = function() {
             var data1 = document.getElementById("dat1") ? document.getElementById("dat1").value : null;
             var data2 = document.getElementById("dat2") ? document.getElementById("dat2").value : null;
             var opt = $scope.search_data; //赋值列表条件
             opt.start_time = data1; //赋值开始时间
             opt.end_time = data2; //赋值结束时间
             $http.get($myconfig.api.Consulting_news_list_b, {
                     params: opt
                 })
                 .then(function(res) {
                     for (var i = 0; i < res.data.data.length; i++) { //添加条数属性
                         res.data.data[i].num = (($scope.search_data.page - 1) * $scope.search_data.limit) + i + 1;
                     }
                     $scope.Consulting_list = res.data.data;
                 })
         }

         //删除咨询单条咨询
         $scope.remove_news = function() {
             $http.get($myconfig.api.Consulting_remove_news, {
                     params: {
                         news_id: news_id
                     }
                 })
                 .then(function(res) {
                     $mydialog.success(res.data.data);
                    //  $scope.news_list_b();
                     $scope.News_count_b()
                 })
         }

         //删除
         var news_id = null;

         function my_callback(val) {
             if (val == true) {
                 $scope.remove_news();
             }
         };

         $scope.fn_delete = function(val) {
             news_id = val;
             $mydialog.inquiry('确定要删除吗？', my_callback)
         };
         $scope.News_count_b();

         //设置置顶
         $scope.top_news = function(news_id, val) {
             $http.post($myconfig.api.Consulting_top_news, {
                     news_id: news_id,
                     top: val
                 })
                 .then(function(res) {
                     $scope.news_list_b();
                 })
         }
         var st = '1992-2-6';
         var arr = st.split('-');

         var birthday = new Date(arr[0], arr[1], arr[2]);

         console.log(birthday);

         console.log(Date.now(birthday));

     }
 })();